package com.role{
	/**
	 * 创建者：薛恒杰
	 * 工程名称：Marbles
	 * 创建时间：Jul 31, 2012 1:01:35 PM
	 * 类说明：Base.as,
	 */
	import com.events.BitmapDataLoaderEvent;
	import com.utils.Collide;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	
	public class Base extends Sprite{
		protected var _collide:Collide;//碰撞系数
		protected var _position:Point;//位置
		
		public var radius:Number;
		protected var bitmap:Bitmap;
		protected var bitmapData:BitmapData;
		
		private var _init:Boolean;
		
		
		[Embed(source="res/a1.png")]
		private var c1:Class;
		[Embed(source="res/a2.png")]
		private var c2:Class;
		[Embed(source="res/a3.png")]
		private var c3:Class;
		public function Base(radius:int = 10)
		{
			super();
			this.radius = radius;
			bitmap = new Bitmap();
			bitmap.x = -32;
			bitmap.y = -44;
			var bm:Bitmap;
			switch(Math.ceil(Math.random() * 3)){
				case 1:{
					bm = new c1() as Bitmap;
					break;
				}
				case 2:{
					bm = new c3() as Bitmap;
					break;
				}
				case 3:{
					bm = new c3() as Bitmap;
					break;
				}
			}
			
			bitmapData = bm.bitmapData;
			addChild(bitmap);
			_init = true;
			drawRectangle(0, 0, 64, 64);
		}
		override public function set x(value:Number):void{
			super.x = value;
			_position.x = value;
		}
		override public function set y(value:Number):void{
			super.y = value;
			_position.y = value;
		}
		public function get position():Point{
			return _position;
		}
		/**
		 * 获取即时碰撞系数。
		 */
		public function get collide():Collide{
			return _collide;
		}
		public function set collide(value:Collide):void{
			_collide = value;
		}
		/**
		 * 承受一个外来碰撞系数。
		 */
		public function setcollide(value:Collide):void{
			//这里把新给进来的碰撞系数进行运算
		}
		public function drawRectangle(x:uint, y:uint, width:uint, height:uint):void{
			if(!_init)return;
			bitmap.bitmapData = new BitmapData(width, height, true, 0x0000000);
			bitmap.bitmapData.copyPixels(bitmapData, new Rectangle(x, y, width, height), new Point());
		}
	}
}